<template>
	<!-- 机加领料单调拨单 -->
	<div>
		<v-alert dense text color="blue-grey">
			请选择开料信息
		</v-alert>
		<v-card>
			<v-card-title>
				<!-- 	<v-tooltip bottom>
					<template v-slot:activator="{ on, attrs }">
						<v-btn class="ml-2" small tile color="success" v-bind="attrs" v-on="on"
							@click="openTransfterOrderDialog()">
							批量创建调拨单
						</v-btn>
					</template>
					<span>选中下方需要创建调拨单的开料信息</span>
				</v-tooltip> -->

				<v-tooltip bottom>
					<template v-slot:activator="{ on, attrs }">
						<v-btn class="ml-2" small tile color="deep-orange" v-bind="attrs" v-on="on"
							@click="openBatchCreateProductionPickingDialog()">
							批量创建领料单
						</v-btn>
					</template>
					<span>选中下方需要创建领料单的开料信息</span>
				</v-tooltip>

				<v-divider class="mx-4" inset vertical></v-divider>

				<v-row class="mt-2">
					<v-col cols="12" sm="3" md="2">
						<v-text-field label="子工单号" v-model="tabTwoRequestOrderSearchPartemer.childrencode" dense
							outlined>
						</v-text-field>
					</v-col>
					<!-- sm="6" md="2" -->
					<v-col cols="12" sm="3" md="2">
						<v-text-field label="项目号" v-model="tabTwoRequestOrderSearchPartemer.projectcode" dense outlined>
						</v-text-field>
					</v-col>
					<v-col cols="12" sm="3" md="2">
						<v-text-field label="项目名称" v-model="tabTwoRequestOrderSearchPartemer.projectname" dense
							outlined>
						</v-text-field>
					</v-col>
					<v-col cols="12" sm="2" md="2">
						<v-text-field label="设备名称" v-model="tabTwoRequestOrderSearchPartemer.equipmentName" dense
							outlined>
						</v-text-field>
					</v-col>
					<!-- ml-n16 前面加n是间距 -->
					<!-- class="ml-n16 mx-auto" -->
					<v-col cols="12" sm="2" md="2">
						<v-btn depressed color="primary" @click="search">查询</v-btn>
						<v-btn class="ml-3" depressed color="primary" @click="refreshApps">
							刷新</v-btn>
					</v-col>
				</v-row>
			</v-card-title>
			<v-data-table :headers="cuttingDetailHeaderList" :items="cuttingDetailDataList" small fixed-header
				item-key="id" dense class="text-no-wrap" show-select loading-text="正在加载请稍等......"
				:loading="cuttingDetailLoading" :options.sync="cuttingDetailOptions" :footer-props="vuetifyDefaultPage"
				:server-items-length="cuttingDetailTotalCount" @input="selectCuttingDetailMultiple">

				<template v-slot:item.picurl="{ item }">
					<a @click="openLookPicsClick(item.picurl)">查看文件</a></td>
				</template>
				<template v-slot:item.isinpruduction="{item}">
					<td>
						<a v-if="item.isinpruduction==1" style="color: #67C23A;">是</a>
						<a v-else>否</a>
					</td>
				</template>
				<template v-slot:item.isprint="{item}">
					<td>
						<a v-if="item.isprint==1" style="color: #67C23A;">是</a>
						<a v-else>否</a>
					</td>
				</template>
				<!-- 
				<template v-slot:item.isstandard="{item}">
					<td class="text-center">{{(item==null?'':( item.isstandard?'标准原材':'下料原材'))}}</td>
				</template> -->
			</v-data-table>
		</v-card>

		<!-- 页签一：创建领料单对话框 -->
		<v-dialog v-model="createProductionPickingDialogVisable" max-width="800px">
			<v-stepper v-model="productionPickingEL">
				<v-stepper-header>
					<v-stepper-step :complete="productionPickingEL > 1" step="1">
						选择领料单信息
					</v-stepper-step>
					<v-divider></v-divider>
					<v-stepper-step step="2">
						选择出货仓库与出货类型
					</v-stepper-step>

					<v-divider></v-divider>

					<v-stepper-step step="3">
						打印领料单
					</v-stepper-step>
				</v-stepper-header>

				<v-stepper-items>
					<!-- 选择物料信息 -->
					<v-stepper-content step="1">
						<v-card>
							<div>
								<v-data-table dense
									:headers="MaterialRequestOrderHeader.filter((val, index, arr) => {return index !==0;})"
									:items="WaitCreateMaterialDataList" :footer-props="vuetifyDefaultPage"
									item-key="materialcode" class="text-no-wrap mt-2" fixed-header>
									<template v-slot:item.needqty="props">
										<v-edit-dialog large @save="saveNeedQty" save-text="保存数量" cancel-text="取消">
											<a>
												{{ props.item.needqty}}
											</a>
											<v-icon small class="mr-2" color="red">
												mdi-pencil
											</v-icon>
											<template v-slot:input>
												<div class="mt-4 text-h6">
													添加领料数量
												</div>
												<v-text-field label="领料数量" :rules="leftNeedQtyRule"
													v-model="props.item.needqty"></v-text-field>
											</template>
										</v-edit-dialog>
									</template>
									<!-- 描述编辑 -->
									<template v-slot:item.description="props">
										<v-edit-dialog large save-text="保存" cancel-text="取消">
											<a>
												{{ props.item.description}}
											</a>
											<v-icon small class="mr-2" color="red">
												mdi-pencil
											</v-icon>
											<template v-slot:input>
												<div class="mt-4 text-h6">
													编辑备注
												</div>
												<v-textarea outlined name="input-7-4" label="备注"
													v-model="props.item.description" :value="props.item.description">
												</v-textarea>
											</template>
										</v-edit-dialog>
									</template>
								</v-data-table>
							</div>
							<div style="text-align: center;">
								<v-spacer></v-spacer>
								<v-btn class="ml-3" color="success" text @click="productionPickingEL = 2">
									下一步
								</v-btn>
								<v-btn class="ml-3" depressed text @click="cancelAddMaterialRequestOrder">
									关闭
								</v-btn>
							</div>
						</v-card>
					</v-stepper-content>

					<!-- 选择出货仓库与出货类型 -->
					<v-stepper-content step="2">
						<v-card>
							<v-card-text>
								<v-select v-model="selectdOutStorage" :items="storageInfoList" label="出货仓库"></v-select>
								<v-select v-model="selectdOutStorageType" :items="outStorageTypeList" label="出货类型">
								</v-select>
							</v-card-text>
							<div style="text-align: center;">
								<v-spacer></v-spacer>
								<v-btn color="primary" text @click="productionPickingEL = 1">
									上一步
								</v-btn>
								<v-btn class="ml-3" color="success" :disabled="selectdOutStorage==null ||selectdOutStorageType==null" text @click="productionPickingEL = 3">
									下一步
								</v-btn>
								<v-btn class="ml-3" depressed text @click="cancelAddMaterialRequestOrder">
									关闭
								</v-btn>
							</div>
						</v-card>
					</v-stepper-content>
					<!-- 提交零料单信息 -->
					<v-stepper-content step="3">
						<v-card>
							<v-card-text>
								<div ref="print" id="print" style="align-items: center;">
									<table class="tab">
										<tbody class="top-tbody">
											<tr>
												<td style="font-weight:bold; text-align:center;" colspan="6">领料单</td>
											</tr>
											<tr style="height:25px;">
												<td style="font-weight:bold">领料单号</td>
												<td style="text-align: center;">
													{{MaterialOtherInfo.bigRequestCode}}
												</td>
												<td style="font-weight:bold">领料部门</td>
												<td style="text-align: center;">
													{{MaterialOtherInfo.departname}}
												</td>
												<td style="font-weight:bold">制单时间</td>
												<td style="text-align: center;">
													{{MaterialOtherInfo.now|dateFormat}}
												</td>
											</tr>
										</tbody>
									</table>
									<table class="tab" style="border-top:none;">
										<tbody class="bottom-tbody">
											<tr>
												<td style="font-weight:bold; text-align:center;" colspan="6">物料信息</td>
											</tr>
											<tr class="tr-head" style="height:25px;">
												<td class="td-bold td-center column-1">物料编码</td>
												<td class="td-bold td-center column-2">物料名称</td>
												<td class="td-bold td-center column-3">物料规格</td>
												<td class="td-bold td-center column-4">数量</td>
												<td class="td-bold td-center column-5">单位</td>
												<td class="td-bold td-center column-5">领料仓库</td>
											</tr>
											<tr v-for="requestOrder in  WaitCreateMaterialDataList"
												:key="requestOrder.materialid" class="tr-body" style="height:25px;">
												<td class="td-body-color td-center column-1 column-body-1">
													{{requestOrder.materialcode}}
												</td>
												<td class="td-body-color td-center column-2 column-body-2">
													{{requestOrder.materialname}}
												</td>
												<td class="td-body-color td-center column-3 column-body-3">
													{{requestOrder.materialspecification}}
												</td>
												<td class="td-body-color td-center column-4 column-body-4">
													{{requestOrder.needqty}}
												</td>
												<td class="td-body-color td-center column-5 column-body-5">
													{{requestOrder.unitname}}
												</td>
												<td class="td-body-color td-center column-5 column-body-5">
													{{selectdOutStorage==null?'':storageInfoList.filter(r=>r.value==selectdOutStorage)[0].text}}
												</td>
											</tr>
										</tbody>
									</table>
									<v-row class="mt-2">
										<v-col cols="3">开单人: {{MaterialOtherInfo.applyusername}}</v-col>
										<v-col cols="3">领料人:</v-col>
										<v-col cols="3">仓管员:</v-col>
										<v-col cols="3">审核人:</v-col>
									</v-row>
								</div>

							</v-card-text>

							<div class="no-print" style="text-align: center;">
								<v-spacer></v-spacer>
								<v-btn color="primary" text @click="productionPickingEL = 2">
									上一步
								</v-btn>
								<v-btn class="ml-3" text color="success" @click="createMaterialRequestOrder">
									打印
								</v-btn>
								<v-btn class="ml-3" text depressed @click="cancelAddMaterialRequestOrder">
									关闭
								</v-btn>
							</div>
						</v-card>

					</v-stepper-content>
				</v-stepper-items>
			</v-stepper>
		</v-dialog>

		<!--页签一： 创建调拨单对话框 -->
		<v-dialog v-model="isOpenTransferOrderDialog" max-width="800px">
			<v-stepper v-model="productionPickingEL">
				<v-stepper-header>
					<v-stepper-step :complete="productionPickingEL > 1" step="1">
						编辑调拨信息
					</v-stepper-step>

					<v-divider></v-divider>

					<v-stepper-step step="2">
						打印信息
					</v-stepper-step>
				</v-stepper-header>

				<v-stepper-items>
					<!-- 选择物料信息 -->
					<v-stepper-content step="1">
						<v-card>
							<v-data-table dense
								:headers="transferOrderHeader.filter((val, index, arr) => {return index !==0;})"
								:items="WaitCreateMaterialDataList" item-key="materialcode" class="text-no-wrap mt-2"
								:footer-props="vuetifyDefaultPage" fixed-header>
								<template v-slot:item.needqty="props">
									<v-edit-dialog large @save="saveNeedQty" save-text="保存数量" cancel-text="取消">
										<a>
											{{ props.item.needqty}}
										</a>
										<v-icon small class="mr-2" color="red">
											mdi-pencil
										</v-icon>
										<template v-slot:input>
											<div class="mt-4 text-h6">
												添加此次调拨数量
											</div>
											<v-text-field label="调拨数量" :rules="leftNeedQtyRule"
												v-model="props.item.needqty"></v-text-field>
										</template>
									</v-edit-dialog>
								</template>

								<template v-slot:item.storagename="props">
									<v-edit-dialog large save-text="保存" cancel-text="取消">
										<a>
											{{ props.item.storagename}}
										</a>
										<v-icon small class="mr-2" color="red">
											mdi-pencil
										</v-icon>
										<template v-slot:input>
											<div class="mt-4 text-h6">
												调拨至目标仓库
											</div>
											<v-select class="mt-6" v-model="props.item.storagename"
												:items="storageInfoList" label="目标仓库"></v-select>

										</template>
									</v-edit-dialog>
								</template>
								<!-- 描述编辑 -->
								<template v-slot:item.description="props">
									<v-edit-dialog large save-text="保存" cancel-text="取消">
										<a>
											{{ props.item.description}}
										</a>
										<v-icon small class="mr-2" color="red">
											mdi-pencil
										</v-icon>
										<template v-slot:input>
											<div class="mt-4 text-h6">
												编辑备注
											</div>
											<v-textarea outlined name="input-7-4" label="备注"
												v-model="props.item.description" :value="props.item.description">
											</v-textarea>
										</template>
									</v-edit-dialog>
								</template>

							</v-data-table>
							<div style="text-align: center;">
								<v-spacer></v-spacer>
								<v-btn class="ml-3" text color="success" @click="productionPickingEL = 2">
									下一步
								</v-btn>
								<v-btn class="ml-3" text depressed @click="cancelAddMaterialRequestOrder">
									关闭
								</v-btn>
							</div>
						</v-card>

					</v-stepper-content>
					<!-- 提交单信息 -->
					<v-stepper-content step="2">
						<v-card>
							<v-card-text>
								<div ref="print" id="print" style="align-items: center;">
									<table class="tab">
										<tbody class="top-tbody">
											<tr>
												<td style="font-weight:bold; text-align:center;" colspan="6">调拨单</td>
											</tr>
											<tr style="height:25px;">
												<td style="font-weight:bold">调拨单号</td>
												<td style="text-align: center;">
													{{MaterialOtherInfo.bigRequestCode}}
												</td>
												<td style="font-weight:bold">调拨部门</td>
												<td style="text-align: center;">
													{{MaterialOtherInfo.departname}}
												</td>
												<td style="font-weight:bold">制单时间</td>
												<td style="text-align: center;">
													{{MaterialOtherInfo.now|dateFormat}}
												</td>
											</tr>
										</tbody>
									</table>
									<table class="tab" style="border-top:none;">
										<tbody class="bottom-tbody">
											<tr>
												<td style="font-weight:bold; text-align:center;" colspan="6">调拨单信息</td>
											</tr>
											<tr class="tr-head" style="height:25px;">
												<td class="td-bold td-center column-1">物料编码</td>
												<td class="td-bold td-center column-2">物料名称</td>
												<td class="td-bold td-center column-3">物料规格</td>
												<td class="td-bold td-center column-4">调拨数量</td>
												<td class="td-bold td-center column-5">单位</td>
												<td class="td-bold td-center column-5">调拨至仓库</td>
											</tr>


											<tr v-for="requestOrder in WaitCreateMaterialDataList"
												:key="requestOrder.materialid+1000" class="tr-body"
												style="height:25px;">
												<td class="td-body-color td-center column-1 column-body-1">
													{{requestOrder.materialcode}}
												</td>
												<td class="td-body-color td-center column-2 column-body-2">
													{{requestOrder.materialname}}
												</td>
												<td class="td-body-color td-center column-3 column-body-3">
													{{requestOrder.materialspecification}}
												</td>
												<td class="td-body-color td-center column-4 column-body-4">
													{{requestOrder.needqty}}
												</td>
												<td class="td-body-color td-center column-5 column-body-5">
													{{requestOrder.unitname}}
												</td>
												<td class="td-body-color td-center column-5 column-body-5">
													{{requestOrder.storagename}}
												</td>
											</tr>
										</tbody>
									</table>
									<v-row class="mt-2">
										<v-col cols="3">开单人: {{MaterialOtherInfo.applyusername}}</v-col>
										<v-col cols="3">调拨人:</v-col>
										<v-col cols="3">仓管员:</v-col>
										<v-col cols="3">审核人:</v-col>
									</v-row>
								</div>
							</v-card-text>
							<div class="no-print" style="text-align: center;">
								<v-spacer></v-spacer>
								<v-btn color="primary" text @click="productionPickingEL = 1">
									上一步
								</v-btn>
								<v-btn class="ml-3" color="success" text @click="createTransferOrder">
									打印
								</v-btn>
								<v-btn class="ml-3" text depressed @click="cancelAddMaterialRequestOrder">
									关闭
								</v-btn>
							</div>
						</v-card>
					</v-stepper-content>
				</v-stepper-items>
			</v-stepper>

		</v-dialog>
		<showfiledialog :filesModel="fileDialogComment"></showfiledialog>
	</div>
</template>

<script>
	import print from 'print-js'
	import showfiledialog from '../../../comments/ShowFilesDialog.vue'
	export default {
		name: 'mes_jj_request_transfter_order',
		components: {
			showfiledialog
		},
		data: () => ({
			fileDialogComment: {
				dialog: false,
				files: []
			},
			cuttingDetailHeaderList: [],
			cuttingDetailDataList: [],
			cuttingDetailLoading: true,
			cuttingDetailTotalCount: 0,
			cuttingDetailOptions: {
				//页数
				page: 1,
				//每页行数
				itemsPerPage: 10
			},
			vuetifyDefaultPage: {
				'items-per-page-text': '每页个数',
				'items-per-page-options': [10, 20, 50, 100]
				// 'items-per-page-all-text': '100'
			},
			//搜索条件
			tabTwoRequestOrderSearchPartemer: {
				materialcode: '',
				materialname: '',
				childrencode: '',
				projectcode: '',
				projectname: '',
				//设备名称
				equipmentName: ''
			},
			checkCuttingDetailList: [],
			MaterialRequestOrderHeader: [],
			transferOrderHeader: [],
			WaitCreateMaterialDataList: [],
			createProductionPickingDialogVisable: false,
			//领料单步骤条
			productionPickingEL: 1,
			leftNeedQtyRule: [
				v => /^[0-9]*$/.test(v) || '请输入合法数字',
				v => v > 0 || '需求量不能小于0'
			],
			MaterialOtherInfo: {},
			isOpenTransferOrderDialog: false,
			storageInfoList: [],
			outStorageTypeList: [],
			selectdOutStorage: null,
			selectdOutStorageType: "21",
		}),
		watch: {
			cuttingDetailOptions: {
				handler() {
					this.loadCuttingDetailList()
				},
				deep: true
			},
		},
		created() {
			this.loadCutDetailHeaderList()
			this.loadMaterialRequestOrderHeader()
			this.loadStorageList()
			this.loadSyncGetOutRdtype()
		},
		methods: {
			//查看图片
			openLookPicsClick(pathstrs) {
				this.fileDialogComment.dialog = true
				this.fileDialogComment.files = JSON.parse(pathstrs)
			},
			//加载仓库信息
			async loadStorageList() {
				const response = await this.$httpRequest({
					url: `MES/MESMaterialRequestOrder/GetStorageList`,
					method: 'get'
				})

				if (response.status == 1) {
					this.storageInfoList = response.data
				}
			},
			//加载出货类型
			async loadSyncGetOutRdtype() {
				const response = await this.$httpRequest({
					url: `MES/MESMaterialRequestOrder/SyncGetOutRdtype`,
					method: 'get'
				})

				if (response.status == 1) {
					this.outStorageTypeList = response.data
				}
			},

			//加载开料信息
			async loadCuttingDetailList() {
				this.cuttingDetailLoading = true
				// var response = await this.$httpRequest({
				// 	url: `MES/MESMaterialRequestOrder/GetAllCuttingDetails?
				// 			equipmentName=${this.tabTwoRequestOrderSearchPartemer.equipmentName}&
				// 			childrenCode=${this.tabTwoRequestOrderSearchPartemer.childrencode}&
				// 			projectCode=${this.tabTwoRequestOrderSearchPartemer.projectcode}&
				// 			projectName=${this.tabTwoRequestOrderSearchPartemer.projectname}&
				// 			pageNumber=${this.cuttingDetailOptions.page}&
				// 			pageSize=${this.cuttingDetailOptions.itemsPerPage}`,
				// 	method: 'get'
				// })

				var response = await this.$httpRequest({
					url: `MES/MESMaterialRequestOrder/LoadChildrenOrderList?
						projectcode=${this.tabTwoRequestOrderSearchPartemer.projectcode}&
						projectname=${this.tabTwoRequestOrderSearchPartemer.projectname}&
						name=${this.tabTwoRequestOrderSearchPartemer.equipmentName}&
						code=${this.tabTwoRequestOrderSearchPartemer.childrencode}&
						type=2&
						pageNumber=${this.cuttingDetailOptions.page}&
						pageSize=${this.cuttingDetailOptions.itemsPerPage}`,
					method: 'get'
				})

				if (response.status == 1) {
					// this.cuttingDetailHeaderList = response.data.headers
					this.cuttingDetailDataList = response.data.childrenList
					this.cuttingDetailTotalCount = response.data.totalCount.value
					this.cuttingDetailLoading = false
				} else {
					this.$message.error('加载开料信息失败')
				}
			},
			//打开调拨单对话框
			async openTransfterOrderDialog() {
				this.loadWaitCreateMaterialDataList(2)
				this.isOpenTransferOrderDialog = true
			},
			//打开批量领料单对话框
			async openBatchCreateProductionPickingDialog() {
				await this.loadWaitCreateMaterialDataList(1)
				this.createProductionPickingDialogVisable = true
			},
			//加载机加物料信息  type: 1：机加领料单 2：机加调拨单
			async loadWaitCreateMaterialDataList(type) {
				var cutdetailIdList = this.checkCuttingDetailList.map(r => r.id)
				if (cutdetailIdList.length <= 0) {
					this.$message.error('请选中开料信息！')
					return
				}
				var response = await this.$httpRequest({
					url: `MES/MESMaterialRequestOrder/GetMaterialDataListByJJ`,
					method: 'post',
					data: {
						type: type,
						childrenIdList: cutdetailIdList
					}
				})

				if (response.status == 1) {
					this.WaitCreateMaterialDataList = response.data.data
					this.MaterialOtherInfo.now = response.data.now
					this.MaterialOtherInfo.departname = response.data.departname
					this.MaterialOtherInfo.bigRequestCode = response.data.bigRequestCode
					this.MaterialOtherInfo.applyusername = response.data.applyusername
				} else {
					this.$message.error(response.info)
				}
			},
			//选中多个开料信息事件
			selectCuttingDetailMultiple(mulitple) {
				this.checkCuttingDetailList = mulitple
			},
			//搜索
			search() {
				this.loadCuttingDetailList()
			},
			//搜索框刷新
			refreshApps() {
				this.tabTwoRequestOrderSearchPartemer = {
					materialcode: '',
					materialname: '',
					childrencode: '',
					projectcode: '',
					projectname: '',
					equipmentName: ''
				}

			},

			cancelAddMaterialRequestOrder() {
				this.productionPickingEL = 1
				this.createProductionPickingDialogVisable = false
				this.isOpenTransferOrderDialog = false
			},
			async createMaterialRequestOrder() {
				var paramterList = []
				this.WaitCreateMaterialDataList.forEach(r => {
					r.parentcode = this.MaterialOtherInfo.bigRequestCode
					r.applydepartmentname = this.MaterialOtherInfo.departname
					r.applyusername = this.MaterialOtherInfo.applyusername
					paramterList.push(r)
				})

				printJS({
					printable: 'print',
					type: 'html',
					targetStyles: ['*'],
					ignoreElements: ['no-print'],
				})

				var response = await this.$httpRequest({
					url: `MES/MESMaterialRequestOrder/AddRequesterOrderForJ?wareHouse=${this.selectdOutStorage}&outStorgeType=${this.selectdOutStorageType}`,
					method: 'post',
					data: paramterList
				})

				if (response.status == 1) {
					this.$message.success(response.info)
					this.createProductionPickingDialogVisable = false
					this.cancelAddMaterialRequestOrder()
					this.loadCuttingDetailList()
					this.selectCuttingDetailMultiple([])
				} else
					this.$message.error(response.info)
			},
			//创建调拨单
			async createTransferOrder() {
				var paramterTransferOrderList = []
				this.WaitCreateMaterialDataList.forEach(r => {
					r.parentcode = this.MaterialOtherInfo.bigRequestCode
					r.applydepartmentname = this.MaterialOtherInfo.departname
					r.applyusername = this.MaterialOtherInfo.applyusername
					var cuts = this.checkCuttingDetailList.filter(c => c.id == r.materialid)
					if (cuts != null && cuts.length > 0) {
						r.childrenid = cuts[0].childrenorderid
						r.projectcode = cuts[0].childrenOrder.projectcode
						r.cuttingdetailid = cuts[0].id
					}
					r.materialid = 0
					paramterTransferOrderList.push({
						'originstragename': r.orgstoragename,
						'targetstoragename': r.storagename,
						'cuttingdetailid': r.cuttingdetailid,
						'childrenid': r.childrenid,
						'projectcode': r.projectcode,
						'description': r.description,
						'transferqty': r.needqty,
						'materialid': 0,
						'materialcode': r.materialcode,
						'materialname': r.materialname,
						'parentcode': r.parentcode,
						'applydepartmentname': r.applydepartmentname,
						'applyusername': r.applyusername,
					})
				})

				printJS({
					printable: 'print',
					type: 'html',
					targetStyles: ['*'],
					ignoreElements: ['no-print'],
				})

				const response = await this.$httpRequest({
					url: `MES/MESMaterialRequestOrder/AddTransferOrderForJ`,
					method: 'post',
					data: paramterTransferOrderList

				})
				if (response.status == 1) {
					this.$message.success(response.info)
					this.loadCuttingDetailList()
				} else
					this.$message.error(response.info)
			},

			//保存需求数量时触发
			saveNeedQty() {
				if (this.checkMaterialRequestOrderList.filter(r => parseInt(r.needqty) > 0).length == this
					.checkMaterialRequestOrderList.length && this.checkMaterialRequestOrderList.length > 0) {
					this.leftCheckMaterialValid = true
				} else {
					this.leftCheckMaterialValid = false
				}
			},
			loadCutDetailHeaderList() {
				this.cuttingDetailHeaderList = [
					{
						text: '项目号',
						value: 'projectcode',
						align: 'center'
					},
					{
						text: '项目名',
						value: 'projectname',
						align: 'center'
					},
					{
						text: '工单号',
						value: 'code',
						align: 'center'
					},
					{
						text: '存货编码',
						value: 'piccode',
						align: 'center'
					},
					{
						text: '存货名称',
						value: 'name',
						align: 'left'
					},
					{
						text: '查看文件',
						value: 'picurl',
						align: 'center'
					},
					{
						text: '规格',
						value: 'specifications',
						align: 'left'
					},
					{
						text: '需求总数',
						value: 'totalcount',
						align: 'center'
					},
					{
						text: '单位名称',
						value: 'unit',
						align: 'center'
					},
					{
						text: '类型',
						value: 'typename',
						align: 'left'
					},
					{
						text: '状态',
						value: 'statusname',
						align: 'left'
					},
				]
			},
			loadMaterialRequestOrderHeader() {

				this.MaterialRequestOrderHeader = [{
						text: "物料代码",
						value: "materialcode"
					},
					{
						text: "物料名称",
						value: "materialname"
					},
					{
						text: "物料规格",
						value: "materialspecification"
					},
					{
						text: "单位",
						value: "unitname"
					},
					// {
					// 	text: "库存数量",
					// 	value: "storgeqty"
					// },
					// {
					// 	text: "仓库",
					// 	value: "storagename"
					// },
				]

				this.transferOrderHeader = [{
						text: '选中项',
						value: 'check'
					},
					{
						text: '调拨数量',
						value: 'needqty'
					},
					{
						text: '目标仓库',
						value: 'storagename'
					},
					{
						text: '备注',
						value: 'description'
					},
					...this.MaterialRequestOrderHeader
				]
				this.transferOrderHeader.pop()
				this.MaterialRequestOrderHeader = [{
						text: '选中项',
						value: 'check'
					},
					{
						text: '需求数量',
						value: 'needqty'
					}, {
						text: '备注',
						value: 'description'
					}, ...this.MaterialRequestOrderHeader
				]
			},

		}

	}
</script>



<style scoped>
	@import url("../../../../../../public/css/print.css");
</style>
